import { getSystemInfoSync } from '@tarojs/taro';
export interface CancellablePromise<T> extends Promise<T> {
    cancel: () => void;
}

export const delay = function (ms: number): CancellablePromise<void> {
    let timeoutId: any;
    const promise = new Promise<void>((resolve) => {
        timeoutId = setTimeout(resolve, ms);
    }) as CancellablePromise<void>;
    promise.cancel = () => {
        timeoutId && clearTimeout(timeoutId);
    };
    return promise;
};
export const sleep = (ms: number) => {
    return new Promise((resolve) => {
        setTimeout(resolve, ms);
    });
};
export const toPX = (value: number) => {
    const clientWidth = getSystemInfoSync().windowWidth;
    return (value * clientWidth) / 750;
};
